﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class Ticksys_ABM_Usuarios_Modificar_Usuario : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            DataSet ds = CargarDDL.ConsultarSectores();

            BoxSector.DataSource = ds.Tables[0];
            BoxSector.DataValueField = "idSector";
            BoxSector.DataTextField = "Sector";
            BoxSector.DataBind();

            DataSet ds_carga = AccesoDatos.Consulta("SELECT * FROM Usuarios WHERE Username = '" + Request.QueryString["id"] + "'");

            BoxNombre.Text = ds_carga.Tables[0].Rows[0]["Nombre"].ToString();
            BoxApellido.Text = ds_carga.Tables[0].Rows[0]["Apellido"].ToString();
            BoxEmail.Text = ds_carga.Tables[0].Rows[0]["Email"].ToString();
            BoxUsername.Text = ds_carga.Tables[0].Rows[0]["Username"].ToString();
            BoxPassword.Text = ds_carga.Tables[0].Rows[0]["Password"].ToString();
            BoxRol.SelectedValue = ds_carga.Tables[0].Rows[0]["Rol"].ToString();
            BoxSector.SelectedValue = ds_carga.Tables[0].Rows[0]["idSector"].ToString();
            BoxInterno.Text = ds_carga.Tables[0].Rows[0]["Interno"].ToString();
        }
    }
  
    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        Sector sector = new Sector();
        sector.idSector = BoxSector.SelectedValue;
        sector.sector = BoxSector.Text;
        Usuario usuario = new Usuario(BoxNombre.Text, BoxApellido.Text, BoxEmail.Text, Request.QueryString["id"], BoxPassword.Text, BoxRol.SelectedValue, sector, BoxInterno.Text);

        GuardarEnBD.Usuario(usuario);
        Response.Redirect("Usuarios.aspx");
    }
}